package com.howells.time.module.account.presenter;


import com.howells.time.base.http.HttpURL;
import com.howells.time.base.http.HttpUtils;
import com.howells.time.base.http.JsonCallback;
import com.howells.time.module.account.view.ChangePswView;
import com.orhanobut.logger.Logger;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

/**
 * Created by Administrator on 2016.4.7.
 */
public class ChangePswPresenterImp implements ChangePswPresenter{
    private ChangePswView changePswView;
    public ChangePswPresenterImp(ChangePswView changePswView){
        this.changePswView=changePswView;
    }

    @Override
    public void changepsw(String oldpsw, String newpsw) {
        Map<String,String> info=new HashMap<>();
        info.put("oldpwd",oldpsw);
        info.put("newpwd",newpsw);
        Logger.d("123456");
        HttpUtils.PostObject(HttpURL.ChangePswApi.toString(), info, new JsonCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                Logger.d(e);
                changePswView.resultMsg("网络异常");
            }

            @Override
            public void onResponse(Map<String, Object> response,int id) {
                if(response.get("message").equals("success")){
                    changePswView.changesuccess();
                }else {
                    if(response.get("errorCode").equals("31"))
                        changePswView.resultMsg("旧密码错误");
                    else
                        changePswView.resultMsg(response.toString());
                }
            }
        });
    }
}
